//
//  SCHotelHomeCell.m
//  shangcheng
//
//  Created by Jie Jie on 2019/7/1.
//  Copyright © 2019 张艳江. All rights reserved.
//

#import "SCHotelHomeCell.h"

CGFloat const k_hotel_cell_lr_out_space = 9;
CGFloat const k_hotel_cell_lr_in_space = 5;
CGFloat const k_hotel_cell_tb_space = 11;

#define k_image_view_h       100
#define k_image_view_w       k_image_view_h * 134/100

@interface SCHotelHomeCell()

@property (nonatomic , strong) UIImageView *hotel_image_view;
@property (nonatomic , strong) UILabel *hotel_name_label;
@property (nonatomic , strong) UILabel *hotel_type_label;
@property (nonatomic , strong) UILabel *hotel_distance_label;
@property (nonatomic , strong) UILabel *hotel_info_r_label;
@property (nonatomic , strong) UILabel *hotel_info_p_label;
@property (nonatomic , strong) UILabel *hotel_info_l_label;
@property (nonatomic , strong) UILabel *hotel_evaluate_label;//评价
@property (nonatomic , strong) UILabel *hotel_price_label;
@property (nonatomic , strong) UILabel *hotel_score_label;//评分


@end

@implementation SCHotelHomeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self=  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createSCHotelView];
    }
    return self;
}


-(void)createSCHotelView{
    
    [self.contentView addSubview:self.hotel_image_view];
    [self.contentView addSubview:self.hotel_name_label];
    [self.contentView addSubview:self.hotel_type_label];
    [self.contentView addSubview:self.hotel_distance_label];
    [self.contentView addSubview:self.hotel_info_l_label];
    [self.contentView addSubview:self.hotel_info_p_label];
    [self.contentView addSubview:self.hotel_info_r_label];
    [self.contentView addSubview:self.hotel_price_label];
    [self.contentView addSubview:self.hotel_score_label];
    
    CGFloat label_h = k_image_view_h * 0.2;
    
    [self.hotel_image_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(k_hotel_cell_tb_space);
        make.height.mas_equalTo(k_image_view_h);
        make.width.mas_equalTo(k_image_view_w);
        make.left.mas_equalTo(k_hotel_cell_lr_out_space);
    }];
    
    CGSize hotel_name_label_size = [self.hotel_name_label.text sizeWithAttributes:@{NSFontAttributeName:self.hotel_name_label.font}];
    CGSize hotel_type_label_size = [self.hotel_type_label.text sizeWithAttributes:@{NSFontAttributeName:self.hotel_type_label.font}];
    CGFloat hotel_name_label_w = hotel_name_label_size.width + 2;
    CGFloat hotel_type_label_w = hotel_type_label_size.width + 2;
    
    [self.hotel_name_label mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.hotel_image_view.mas_right).mas_offset(k_hotel_cell_lr_in_space);
        make.top.mas_equalTo(k_hotel_cell_tb_space);
        make.height.mas_equalTo(label_h);
        make.width.mas_equalTo(hotel_name_label_w);
    }];
    
    [self.hotel_type_label mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.hotel_name_label.mas_right).mas_offset(k_hotel_cell_lr_in_space);
    make.top.mas_equalTo(self.hotel_name_label.mas_top).mas_offset(3);
    make.bottom.mas_equalTo(self.hotel_name_label.mas_bottom).mas_offset(-1);
        make.width.mas_equalTo(hotel_type_label_w);
    }];
    
    [self.hotel_distance_label mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(-k_hotel_cell_lr_out_space);
    make.top.mas_equalTo(self.hotel_type_label.mas_top).mas_offset(2);
    make.bottom.mas_equalTo(self.hotel_type_label.mas_bottom).mas_offset(-1);
        make.width.mas_equalTo(100);
    }];
    
    CGSize hotel_info_l_label_size = [self.hotel_info_l_label.text sizeWithAttributes:@{NSFontAttributeName:self.hotel_info_l_label.font}];
    CGSize hotel_info_p_label_size = [self.hotel_info_p_label.text sizeWithAttributes:@{NSFontAttributeName:self.hotel_info_p_label.font}];
    CGSize hotel_info_r_label_size = [self.hotel_info_r_label.text sizeWithAttributes:@{NSFontAttributeName:self.hotel_info_r_label.font}];
    CGFloat hotel_info_l_label_w = hotel_info_l_label_size.width + 10;
    CGFloat hotel_info_p_label_w = hotel_info_p_label_size.width + 10;
    CGFloat hotel_info_r_label_w = hotel_info_r_label_size.width + 10;
    
    CGFloat info_label_h = label_h * 18 /20;
    CGFloat info_label_space = 2;
    
    [self.hotel_info_l_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.hotel_image_view.mas_right).mas_offset(k_hotel_cell_lr_in_space);
    make.top.mas_equalTo(self.hotel_name_label.mas_bottom).mas_offset(9);
        make.height.mas_equalTo(info_label_h);
        make.width.mas_equalTo(hotel_info_l_label_w);
    }];
    
    [self.hotel_info_p_label mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.hotel_info_l_label.mas_right).mas_offset(info_label_space);
        make.top.mas_equalTo(self.hotel_info_l_label.mas_top);
        make.height.mas_equalTo(info_label_h);
        make.width.mas_equalTo(hotel_info_p_label_w);
    }];
    
    [self.hotel_info_r_label mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.hotel_info_p_label.mas_right).mas_offset(info_label_space);
        make.top.mas_equalTo(self.hotel_info_l_label.mas_top);
        make.height.mas_equalTo(info_label_h);
        make.width.mas_equalTo(hotel_info_r_label_w);
    }];
    
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = RGB(255, 244, 229);
    [self.contentView addSubview:view];
    [view addSubview:self.hotel_evaluate_label];
    
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.hotel_image_view.mas_right).mas_offset(k_hotel_cell_lr_in_space);
    make.top.mas_equalTo(self.hotel_info_l_label.mas_bottom).mas_offset(8);
        make.height.mas_equalTo(22);
        make.right.mas_equalTo(-k_hotel_cell_lr_out_space);
    }];
    
    [self.hotel_evaluate_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.and.right.and.bottom.mas_equalTo(0);
    }];
    
    
    CGSize hotel_price_label_size = [self.hotel_price_label.text sizeWithAttributes:@{NSFontAttributeName:self.hotel_price_label.font}];
    CGFloat hotel_price_label_w = hotel_price_label_size.width + 2;
    
    [self.hotel_price_label mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.hotel_image_view.mas_right).mas_offset(k_hotel_cell_lr_in_space);
        make.top.mas_equalTo(view.mas_bottom).mas_offset(4);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(hotel_price_label_w);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @"起";
    label.textColor = RGB(175,175, 175);
    label.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(self.hotel_price_label.mas_right).mas_offset(2);
    make.top.mas_equalTo(self.hotel_price_label.mas_bottom).mas_offset(8);
    make.bottom.mas_equalTo(self.hotel_price_label.mas_bottom).mas_offset(-3);
        make.width.mas_equalTo(hotel_price_label_w);
    }];
    
    [self.hotel_score_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-k_hotel_cell_lr_out_space);
        make.top.mas_equalTo(view.mas_bottom).mas_offset(7);
        make.height.mas_equalTo(21);
        make.width.mas_equalTo(150);
    }];
}


#pragma mark 初始化
-(UIImageView *)hotel_image_view{
    
    if (_hotel_image_view == nil) {
        _hotel_image_view = [[UIImageView alloc] init];
        _hotel_image_view.layer.masksToBounds = YES;
        _hotel_image_view.layer.cornerRadius = 3;
        _hotel_image_view.backgroundColor =  RGB(219, 52, 52);
    }
    return _hotel_image_view;
}

-(UILabel *)hotel_name_label{
    
    if (_hotel_name_label == nil) {
        _hotel_name_label = [[UILabel alloc] init];
        _hotel_name_label.text = @"第七季商务酒店";
        _hotel_name_label.font = [UIFont systemFontOfSize:14.0f];
        _hotel_name_label.textColor = RGB(51, 51, 51);
        
    }
    return _hotel_name_label;
}

-(UILabel *)hotel_type_label{
    
    if (_hotel_type_label == nil) {
        _hotel_type_label = [[UILabel alloc] init];
        _hotel_type_label.text = @"度假酒店";
        _hotel_type_label.font = [UIFont systemFontOfSize:12.0f];
        _hotel_type_label.textColor = RGB(231, 157, 58);
       
    }
    return _hotel_type_label;
}

-(UILabel *)hotel_distance_label{
    
    if (_hotel_distance_label == nil) {
        _hotel_distance_label = [[UILabel alloc] init];
        _hotel_distance_label.text = @">1500m";
        _hotel_distance_label.font = [UIFont systemFontOfSize:10.0f];
        _hotel_distance_label.textColor = RGB(175, 175, 175);
        _hotel_distance_label.textAlignment = NSTextAlignmentRight;
        
    }
    return _hotel_distance_label;
}

-(UILabel *)hotel_info_l_label{
    
    if (_hotel_info_l_label == nil) {
        _hotel_info_l_label = [[UILabel alloc] init];
        _hotel_info_l_label.text = @"含早";
        _hotel_info_l_label.font = [UIFont systemFontOfSize:10.0f];
        _hotel_info_l_label.textColor = RGB(231, 157, 58);
        _hotel_info_l_label.layer.borderWidth = 1;
        _hotel_info_l_label.layer.masksToBounds = YES;
        _hotel_info_l_label.layer.cornerRadius = 8;
        _hotel_info_l_label.layer.borderColor = RGB(231, 157, 58).CGColor;
        _hotel_info_l_label.backgroundColor = [UIColor whiteColor];
        _hotel_info_l_label.textAlignment = NSTextAlignmentCenter;
        
    }
    return _hotel_info_l_label;
}

-(UILabel *)hotel_info_p_label{
    
    if (_hotel_info_p_label == nil) {
        _hotel_info_p_label = [[UILabel alloc] init];
        _hotel_info_p_label.text = @"免费停车";
        _hotel_info_p_label.font = [UIFont systemFontOfSize:10.0f];
        _hotel_info_p_label.textColor = RGB(231, 157, 58);
        _hotel_info_p_label.layer.borderWidth = 1;
        _hotel_info_p_label.layer.masksToBounds = YES;
        _hotel_info_p_label.layer.cornerRadius = 8;
        _hotel_info_p_label.layer.borderColor = RGB(231, 157, 58).CGColor;
        _hotel_info_p_label.backgroundColor = [UIColor whiteColor];
        _hotel_info_p_label.textAlignment = NSTextAlignmentCenter;
        
    }
    return _hotel_info_p_label;
}

-(UILabel *)hotel_info_r_label{
    
    if (_hotel_info_r_label == nil) {
        _hotel_info_r_label = [[UILabel alloc] init];
        _hotel_info_r_label.text = @"免费Wi-Fi";
        _hotel_info_r_label.font = [UIFont systemFontOfSize:10.0f];
        _hotel_info_r_label.textColor = RGB(231, 157, 58);
        _hotel_info_r_label.layer.borderWidth = 1;
        _hotel_info_r_label.layer.masksToBounds = YES;
        _hotel_info_r_label.layer.cornerRadius = 8;
        _hotel_info_r_label.layer.borderColor = RGB(231, 157, 58).CGColor;
        _hotel_info_r_label.backgroundColor = [UIColor whiteColor];
        _hotel_info_r_label.textAlignment = NSTextAlignmentCenter;
        
    }
    return _hotel_info_r_label;
}

-(UILabel *)hotel_evaluate_label{
    
    if (_hotel_evaluate_label == nil) {
        _hotel_evaluate_label = [[UILabel alloc] init];
        _hotel_evaluate_label.text = @"用户说：环境很好，设施齐全，很干净";
        _hotel_evaluate_label.textAlignment = NSTextAlignmentLeft;
        _hotel_evaluate_label.font = [UIFont systemFontOfSize:10.0f];
        
    }
    return _hotel_evaluate_label;
}

-(UILabel *)hotel_price_label{
    
    if (_hotel_price_label == nil) {
        _hotel_price_label = [[UILabel alloc] init];
        _hotel_price_label.text = @"￥288";
        _hotel_price_label.textAlignment = NSTextAlignmentLeft;
        _hotel_price_label.font = [UIFont systemFontOfSize:18.0f];
        _hotel_price_label.textColor = RGB(219, 52, 52);
    }
    return _hotel_price_label;
}

-(UILabel *)hotel_score_label{
    
    if (_hotel_score_label == nil) {
        _hotel_score_label = [[UILabel alloc] init];
        _hotel_score_label.text = @"4.5分";
        _hotel_score_label.textAlignment = NSTextAlignmentRight;
        _hotel_score_label.font = [UIFont systemFontOfSize:15.0f];
        _hotel_score_label.textColor = RGB(219, 52, 52);
    }
    return _hotel_score_label;
}

@end
